package xin.mashibo.artcobutest.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;

import xin.mashibo.artcobutest.R;
import xin.mashibo.artcobutest.vo.CardOwnerExtend;

import static xin.mashibo.artcobutest.constant.ServiceConstant.CARDOWNER_KEY;

public class CardOwnerActivity extends AppCompatActivity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.listview);
        setTitle(getString(R.string.cardOwnerActivityTitle));
        CardOwnerExtend extend = getIntent().getBundleExtra(CARDOWNER_KEY).getParcelable(CARDOWNER_KEY);
        ListView listView = findViewById(R.id.list_view);
        ArrayAdapter<String> adapter = new ArrayAdapter<String>(this, android.R.layout.simple_list_item_1, generateDataList(extend));
        listView.setAdapter(adapter);
    }

    /**
     * 根据卡片所有人信息生成列表
     *
     * @param extend 卡片所有人信息
     * @return 数据列表
     */
    private List<String> generateDataList(CardOwnerExtend extend) {
        List<String> dataList = new ArrayList<>();
        dataList.add("OwnerId：" + extend.ownerId);
        dataList.add("证件号码：" + extend.ownerLicenseNumber);
        dataList.add("证件类型：" + extend.ownerLicenseType);
        dataList.add("所有人姓名：" + extend.ownerName);
        dataList.add("StaffId：" + extend.staffId);
        return dataList;
    }

    /**
     * 启动该活动
     *
     * @param context 发起启动的活动
     * @param bundle  数据bundle
     */
    public static void actionStart(Context context, Bundle bundle) {
        Intent intent = new Intent(context, CardOwnerActivity.class);
        intent.putExtra(CARDOWNER_KEY, bundle);
        context.startActivity(intent);
    }
}
